{extend name="base:base" /}
{block name="body"}
<fieldset class="layui-elem-field layui-field-title mt-15">
    <legend>{present name="info"}编辑{else /}新增{/present}公告</legend>
</fieldset>
<form class="layui-form" action="{:Url::build('renew')}" method="post">
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md6">
            <div class="layui-form-item">
                <label class="layui-form-label">公告标题</label>
                <div class="layui-input-block">
                    <input type="text" name="title" placeholder="输入公告标题" lay-verify="required"
                           value="{$info.title ?? ''}" class="layui-input">
                    <div class="layui-form-mid layui-word-aux">公告标题</div>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">通知区域</label>
        <div class="layui-input-inline">
            <select name="type">
                <option value="0">前后台</option>
                <option value="1">前台</option>
                <option value="2">后台</option>
            </select>
            <div class="layui-form-mid layui-word-aux">所通知的区域</div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md6">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">公告描述</label>
                <div class="layui-input-block">
            <textarea placeholder="输入公告描述" name="description" rows="5"
                      class="layui-textarea">{$info.description ?? ''}</textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-row">
        <div class="layui-col-xs12 layui-col-md12">
            <div class="layui-form-item layui-form-text">
                <label class="layui-form-label">正文内容</label>
                <div class="layui-input-block">
                    <textarea name="content" id="layedit" lay-verify="content" style="display: none">{$info.content ?? ''}</textarea>
                </div>
            </div>
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input type="hidden" name="id" value="{$info.id ?? ''}">
            <button class="layui-btn" lay-submit="" lay-filter="action">立即提交</button>
            <button class="layui-btn layui-btn-primary retreat">取消</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    UrlHighlight("{:Url::build('Notice/index')}");
    setChoose("type", "{$info:type ?? 1}");
    layui.use(['jquery', 'form', 'layer', 'layedit'], function () {
        //编辑器
        layui.layedit.set({
            uploadImage: {
                url: "{:Url::build('fileUpload')}", //接口url
                type: 'post' //默认post
            }
        });
        var contents = layui.layedit.build('layedit', {height: 400});
        layui.form.verify({
            content: function(){layui.layedit.sync(contents);}//同步编辑器内容
        });
        //监听提交
        layui.form.on('submit(action)', function (data) {
            layui.layedit.sync(contents);
            layui.$.post(data.form.action, data.field, function (info) {
                status_load(info, data.elem);
            })
            return false;
        });
    })
</script>
{/block}